home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / mxcode / soundx / voclook.c < prev    next >
C/C++ Source or Header  |  1993-06-26  |  4KB  |  128 lines

  1.  
  2. /* Copyright 1993 by Peter Sprenger   Pete@amber.dinoco.de
  3.  *                   5014 Kerpen 3
  4.  *                   Germany
  5.  *
  6.  * Permission to use, copy, modify, and distribute this
  7.  * software and its documentation for any purpose and without
  8.  * fee is hereby granted, provided that the above copyright
  9.  * notice appear in all copies.  The author Peter Sprenger
  10.  * makes no representations about the suitability of this
  11.  * software for any purpose.  It is provided "as is" without
  12.  * express or implied warranty.
  13.  */
  14.  
  15.  
  16. #include <stddef.h>
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include <dos.h>
  20. #include <io.h>
  21. #include <fcntl.h>
  22. #include <alloc.h>
  23. #include <sys\stat.h>
  24. #include "mydef.h"
  25.  
  26. void main(int argc,char *argv[])
  27. {
  28.     int file;
  29.     WORD ret;
  30.     struct stat mystat;
  31.     long length,TC;
  32.     char huge *base,huge *base2;
  33.     DWORD blklen,rate;
  34.     BYTE tmp,tmp2,huge *ptr;
  35.  
  36.     if(argc==2)
  37.     {
  38.         if(stat(argv[1],&mystat))
  39.         {
  40.             printf("file %s does'nt exist\n",argv[1]);
  41.             return;
  42.         }
  43.         length=mystat.st_size;
  44.         printf("File Size: %lu\n",length);
  45.         base=farmalloc(length);
  46.         if(!base)
  47.         {
  48.             printf("Not enough memory!");
  49.             return;
  50.         }
  51.         file=open(argv[1],O_RDONLY|O_BINARY);
  52.         if(file== -1)
  53.         {
  54.             printf("Cannot open file!");
  55.             if(base) farfree(base);
  56.             return;
  57.         }
  58.         base2=base;
  59.         do
  60.         {
  61.             ret=read(file,base2,32700);  /* do not use this call in small model! */
  62.             base2+=ret;
  63.         } while(ret==32700);
  64.         close(file);
  65.  
  66.         ptr=base;
  67.         if(strncmp(ptr,"Creative Voice File\x1a",20) || *((WORD *)ptr+11)!=(~*((WORD *)ptr+12)+0x1234))
  68.         {
  69.             printf("No voc file!\n");
  70.             if(base) farfree(base);
  71.             return;
  72.         }
  73.         printf("Creative Voice File\n");
  74.         printf("version: %d.%d\n\n",*(ptr+0x17),*(ptr+0x16));
  75.  
  76.         ptr+=*((WORD *)ptr+10);
  77.         while(*ptr)
  78.         {
  79.             blklen=((DWORD)(*(ptr+3))<<16)+ *((WORD *)(ptr+1))+4;
  80.             switch(*ptr)
  81.             {
  82.                 case 1: printf("Block Type-1 Voice Data\n");
  83.                         printf("Sample Rate: %ld\n",1000000L/(256l-*(ptr+4)));
  84.                         printf("PACK: ");
  85.                         tmp=*(ptr+5);
  86.                         if(tmp==0) printf("8-bit unpacked\n");
  87.                         if(tmp==1) printf("4-bit packed\n");
  88.                         if(tmp==2) printf("2.6-bit packed\n");
  89.                         if(tmp==3) printf("2-bit packed\n");
  90.                     break;
  91.                 case 2: printf("Block Type-2 Voice Continuation\n\n");
  92.                     break;
  93.                 case 3: printf("Block Type-3 Silence\n");
  94.                         printf("Length: %u periods\n",*((WORD *)(ptr+4)));
  95.                         printf("Sample Rate: %ld\n",1000000L/(256l-*(ptr+6)));
  96.                     break;
  97.                 case 4: printf("Block Type-4 Marker\n");
  98.                     break;
  99.                 case 5: printf("Block Type-5 ASCII Text\n");
  100.                         printf("Text: %s\n",ptr+4);
  101.                     break;
  102.                 case 6: printf("Block Type-6 Repeat Loop\n");
  103.                         printf("Count: %u\n",*((WORD *)(ptr+4)));
  104.                     break;
  105.                 case 7: printf("Block Type-7 End Repeat Loop\n");
  106.                     break;
  107.                 case 8: printf("Block Type-8 Extended Block\n");
  108.                         rate=256000000L/(65536l-*((WORD *)ptr+2));
  109.                         tmp2=*(ptr+7);
  110.                         if(tmp2) rate>>=1;
  111.                         printf("Sample Rate: %lu\n",rate);
  112.                         tmp=*(ptr+6);
  113.                         if(tmp==0) printf("8-bit unpacked\n");
  114.                         if(tmp==1) printf("4-bit packed\n");
  115.                         if(tmp==2) printf("2.6-bit packed\n");
  116.                         if(tmp==3) printf("2-bit packed\n");
  117.                         if(tmp2) printf("Stereo\n");
  118.                         else printf("Mono\n");
  119.                     break;
  120.                 default: printf("Unkown Block Type-%u!\n",*ptr);
  121.             }
  122.             ptr+=blklen;
  123.             printf("Blocklength: %lu\n\n",blklen-4);
  124.         }
  125.         printf("Block Type-0 Terminator\n");
  126.     }
  127.     else printf("usage: voclook filename\n");
  128. }